package com.ygo.feihua.Management;
import com.ygo.feihua.BmobTable.*;
import cn.bmob.v3.*;
import android.content.*;
import com.ygo.feihua.*;
import java.util.*;
import com.ygo.feihua.util.*;

/*
*本地用户管理类
*time:2017.6.10
*/
public class UserManagement 
{
	private static UserManagement userManagement=new UserManagement();
	//本地用户对象
	private MyUser user;
	
	private List<LogInListener> llList;
	
	private UserManagement(){
		user=BmobUser.getCurrentUser(MyUser.class);
		llList=new ArrayList<LogInListener>();
	}
	
	//刷新本地用户对象
	public void sxUser(){
		user=BmobUser.getCurrentUser(MyUser.class);
		for(LogInListener ll:llList){
			if(user==null){
				ll.logout();
			}else{
				ll.login(user);
			}
		}
		
	}
	
	//获取本地用户对象
	public MyUser getUser(){
		return user;
	}
	
	//退出登录
	public void logOutUser(){
		BmobUser.logOut();
		sxUser();
	}
	
	//登录
	public void logInUser(Context context){	
		DialogUtils du=DialogUtils.getdx(context);
		du.dialoglogin();
		
	}
	
	public void addLogInLostener(LogInListener ll){
		llList.add(ll);
	}
	
	public static UserManagement getDx(){
		return userManagement;
	}
}
